home *** CD-ROM | disk | FTP | other *** search
- <%
- '+-------------------------------------------------------------------------
- '
- ' Microsoft Windows Media
- ' Copyright (C) Microsoft Corporation. All rights reserved.
- '
- ' File: wmsconnect.inc
- '
- ' Contents: Establishes connection with ASP glue COM object;
- ' Connects to the server OM
- ' Initializes several global variables such as unhashed server name
- '
- ' Dependencies: locStrings.inc, wmsConstants.inc
- '
- '--------------------------------------------------------------------------
-
- Dim s_WMSAdmin
- Dim g_objServer
- Dim g_objPubPoint
- Dim g_strServerName
- Dim g_strPubPointName
-
- Dim g_dwConnectionFailureCode
- Dim g_bFailedToStartService
- Dim g_strDecodedServerName
- Dim g_strEncodedServerName
- Dim g_strEncodedPubPointName
- Dim g_strPubPointID
-
- Dim g_strQueryString
- Dim g_bSecureConnection
-
- ' Browser type
- Dim g_bMSIE
- Dim g_bNetscape
- Dim g_bOpera
-
- ' Browser details
- Dim g_dwBrowserType
- Dim g_curBrowserVersion
- Dim g_strUserAgent
- Dim g_strQueryStringServer
- Dim g_strQueryStringServerOp
- Dim g_CurPageSessionHash
-
- Dim qs
- Dim posting
-
- Server.ScriptTimeout = 90
-
- g_objServer = empty
- g_objPubPoint = empty
-
- g_bMSIE = TRUE
- g_bNetscape = FALSE
- g_bOpera = FALSE
-
- g_curBrowserVersion = "0.0"
- g_strUserAgent = ""
- g_strQueryStringServer = ""
- g_strQueryStringServerOp = ""
- g_CurPageSessionHash = empty
-
- Set qs = Request.QueryString
- Set posting = Request.Form
-
- on error resume next
-
- ' Connect to WMSASPAdmin.DLL -- binds us to the Windows Media Server's Object Model
- '
- ' NOTE: If this fails, then the Windows Media Server's administration components
- ' have not been installed properly. Performing the following actions may help:
- '
- ' pushd %sytemroot%\system32\windows media\server\admin\web\
- ' regsvr32 wmsaspadmin.dll
- '
- Set s_WMSAdmin = Session( "WMSAdmin" )
- if( IsEmpty( s_WMSAdmin ) ) then
- Set s_WMSAdmin = Server.CreateObject("WMSAdminRemote.ASPAdmin")
- Set Session("WMSAdmin") = s_WMSAdmin
- end if
-
- if( IsEmpty( s_WMSAdmin ) ) then
- if g_bDebugMode then
- STOP ' WMSASPADMIN.DLL has not been registered or is inaccessible
- end if
- end if
-
- g_strQueryStringServer = RemoveDangerousCharacters( trim( qs( "server" ) ) )
- if( MAX_LEN_SERVERNAME < Len( g_strQueryStringServer ) ) then
- g_strQueryStringServer = ""
- end if
-
- g_strEncodedServerName = RemoveDangerousCharacters( ServerHashKeyToName( g_strQueryStringServer ) )
- g_strDecodedServerName = SafeUnescape( g_strEncodedServerName )
- g_strPubPointID = ""
- g_strEncodedPubPointName = ""
- g_strQueryStringServerOp = RemoveDangerousCharacters( trim( qs( "serverop" ) ) )
- if( MAX_LEN_OP < Len( g_strQueryStringServerOp ) ) then
- g_strQueryStringServerOp = ""
- end if
-
- g_strQueryString = Request.ServerVariables( "PATH_INFO" ) & "?" & RemoveDangerousCharacters( trim( qs ) )
-
- 'g_bSecureConnection = ( 0 = StrComp( "1", Request.ServerVariables( "SERVER_PORT_SECURE" ), vbTextCompare ) )
- g_bSecureConnection = CBool( 0 = StrComp( "on", Request.ServerVariables( "HTTPS" ), vbTextCompare ) )
-
- Set g_CurPageSessionHash = Session( "CurrentPage" )
- if IsEmpty( g_CurPageSessionHash ) then
- ' Shouldn't happen-- this is performed in global.asa
- Set g_CurPageSessionHash = Server.CreateObject("Scripting.Dictionary")
- Set Session( "CurrentPage" ) = g_CurPageSessionHash
-
- if( FALSE = g_CurPageSessionHash.Exists( "Default" ) ) then
- g_CurPageSessionHash.Add "Default", "server_status.asp"
- end if
-
- if( FALSE = g_CurPageSessionHash.Exists( UCase( g_strQueryStringServer ) ) ) then
- g_CurPageSessionHash.Add UCase( g_strQueryStringServer ), "server_status.asp"
- end if
- end if
-
- 'BrowserSniff
- 'PickStyleSheet
-
-
- '////////////////////////////////////////////////////////////////'
- ' Subroutines '
- '////////////////////////////////////////////////////////////////'
-
-
- '////////////////////////////////////////////////////////////////
- 'Sub BrowserSniff()
- g_curBrowserVersion = Session( "BrowserVersion" )
- if( 0 = Len( g_curBrowserVersion ) ) then
-
- Dim strBrowser
- Dim objBrowseCap
-
- err.Clear
-
- g_dwBrowserType = brUnknown
- g_strUserAgent = Request.ServerVariables( "HTTP_USER_AGENT" )
-
- Set objBrowseCap = Server.CreateObject( "MSWC.BrowserType" )
- if( 0 = err.number ) then
- strBrowser = objBrowseCap.browser
- if( 0 = StrComp( "IE", strBrowser, vbTextCompare ) ) then
- g_dwBrowserType = brMSIE
- elseif( 0 = StrComp( "Netscape", strBrowser, vbTextCompare ) ) then
- g_dwBrowserType = brNetscape
- elseif( 0 = StrComp( "Opera", strBrowser, vbTextCompare ) ) then
- g_dwBrowserType = brOpera
- end if
-
- g_curBrowserVersion = CCur( objBrowseCap.version )
- end if
-
- if( brUnknown = g_dwBrowserType ) then
- if( 0 < InStr( 1, g_strUserAgent, "MSIE", vbTextCompare ) ) then
- g_dwBrowserType = brMSIE
- g_curBrowserVersion = CCur( Mid( g_strUserAgent, InStr( 1, g_strUserAgent, "MSIE", vbTextCompare ) + 5, 3 ) )
- if( 0 >= g_curBrowserVersion ) then
- g_curBrowserVersion = CCur( Mid( g_strUserAgent, InStr( 1, g_strUserAgent, "MSIE", vbTextCompare ) + 5, 1 ) )
- end if
- elseif( 0 < InStr( 1, g_strUserAgent, "Opera", vbTextCompare ) ) then
- g_dwBrowserType = brOpera
- g_curBrowserVersion = CCur( Mid( g_strUserAgent, InStr( 1, g_strUserAgent, "Opera", vbTextCompare ) + 6, 1 ) )
- else
- g_dwBrowserType = brNetscape
- if( 0 < InStr( 1, g_strUserAgent, "Gecko", vbTextCompare ) ) then
- g_curBrowserVersion = CCur( Mid( g_strUserAgent, 9, 1 ) )
- else
- g_curBrowserVersion = CCur( Mid( g_strUserAgent, InStrRev( g_strUserAgent, "/", -1, vbTextCompare ) + 1, 1 ) )
- if( 0 = g_curBrowserVersion ) then
- g_curBrowserVersion = CCur( Mid( g_strUserAgent, InStr( g_strUserAgent, "/", -1, vbTextCompare ) + 1, 1 ) )
- if( 2 >= g_curBrowserVersion ) then
- if( 0 < InStr( 1, g_strUserAgent, "Gecko", vbTextCompare ) ) then
- g_curBrowserVersion = CCur( "5.0" )
- end if
- end if
- end if
- end if
- end if
- end if
-
- Session( "UserAgent" ) = g_strUserAgent
- Session( "BrowserType" ) = g_dwBrowserType
- Session( "BrowserVersion" ) = g_curBrowserVersion
- else
- g_strUserAgent = Session( "UserAgent" )
- g_dwBrowserType = Session( "BrowserType" )
- ' g_curBrowserVersion = Session( "BrowserVersion" )
- end if
-
- ' Set depricated flags
- if( brMSIE = g_dwBrowserType ) then
- g_bMSIE = TRUE
- g_bNetscape = FALSE
- g_bOpera = FALSE
- elseif( brNetscape = g_dwBrowserType ) then
- g_bMSIE = FALSE
- g_bNetscape = TRUE
- g_bOpera = FALSE
- elseif( brOpera = g_dwBrowserType ) then
- g_bMSIE = FALSE
- g_bNetscape = FALSE
- g_bOpera = TRUE
- end if
-
- 'End Sub
-
-
- '////////////////////////////////////////////////////////////////
- 'Sub PickStyleSheet()
-
- 'BrowserSniff
-
- ' g_strUserAgent = Session( "UserAgent" )
- ' g_dwBrowserType = Session( "BrowserType" )
- ' g_curBrowserVersion = Session( "BrowserVersion" )
-
- if( 0 = Len( Session( "cssName" ) ) ) then
- ' bSecureConnection = CBool( 0 = StrComp( "on", Request.ServerVariables( "HTTPS" ), vbTextCompare ) )
- ' if( TRUE = bSecureConnection ) then
- ' strProtocol = CStr( "https://" )
- ' else
- ' strProtocol = CStr( "http://" )
- ' end if
-
- if( brMSIE = g_dwBrowserType ) then
- if( MIN_MSIE_VERSION <= g_curBrowserVersion ) then
- if( 0 >= InStr( g_strUserAgent, "Windows" ) ) then
- Session( "cssName" ) = "css/wms_macie_admin.css"
- else
- Session( "cssName" ) = "css/wmsadmin.css"
- end if
- end if
- elseif( brNetscape = g_dwBrowserType ) then
- if( MIN_NSCP_VERSION <= g_curBrowserVersion ) then
- Session( "cssName" ) = "css/wms_ns6_admin.css"
- end if
- elseif( brOpera = g_dwBrowserType ) then
- if( MIN_OPERA_VERSION <= g_curBrowserVersion ) then
- Session( "cssName" ) = "css/wms_ns6_admin.css"
- end if
- else
- Session( "cssName" ) = "css/wmsadmin.css" & g_dwBrowserType
- end if
- end if
-
- 'End Sub
-
-
- '////////////////////////////////////////////////////////////////
- Sub ConnectToNamedServer( strServerName, strServerOp, byRef objServer )
- if( MAX_LEN_SERVERNAME < Len( trim( strServerName ) ) ) then
- Exit Sub
- end if
-
- if( MAX_LEN_OP < Len( trim( strServerOp ) ) ) then
- Exit Sub
- end if
-
- on error resume next
- g_dwConnectionFailureCode = WMS_SERVER_UNKNOWN
- g_bFailedToStartService = FALSE
-
- if( 0 = strcomp( "kill", strServerOp, vbTextCompare ) ) then
- err.clear
- s_WMSAdmin.StopService( strServerName )
- g_dwConnectionFailureCode = s_WMSAdmin.GetServiceStatus( strServerName )
- if( ( WMS_SERVICE_STOPPED <> g_dwConnectionFailureCode ) or ( 0 <> err.number ) ) then
- s_WMSAdmin.StopService( strServerName )
- err.Clear
- g_dwConnectionFailureCode = s_WMSAdmin.GetServiceStatus( strServerName )
- end if
- objServer = empty
- if( WMS_SERVICE_STOPPED <> g_dwConnectionFailureCode ) then
- Response.Redirect( "/wmssecure/admin.asp?server=" & g_strQueryStringServer & "&stopping=true" )
- end if
-
- Set Session( "objCachedServer" ) = Empty
- Session( "strCachedServerName" ) = ""
- Set Session( "objCachedPP" ) = Empty
- Session( "strCachedPPID" ) = ""
- Session( "dwCachedServerStatus" ) = -1
-
- Exit Sub
-
- elseif( 0 = strcomp( "start", strServerOp, vbTextCompare ) ) then
-
- Set Session( "objCachedServer" ) = Empty
- Session( "strCachedServerName" ) = ""
- Set Session( "objCachedPP" ) = Empty
- Session( "strCachedPPID" ) = ""
- Session( "dwCachedServerStatus" ) = -1
-
- Session( "ConnectionFailure" ) = FALSE
- if( 0 < Len( strServerName ) ) then
- s_WMSAdmin.StartService( strServerName )
- g_dwConnectionFailureCode = s_WMSAdmin.GetServiceStatus( strServerName )
- if( WMS_SERVICE_STARTING = g_dwConnectionFailureCode ) then
- err.clear
- Session( "ConnectionFailure" ) = FALSE
- elseif( ( WMS_SERVICE_STARTED <> g_dwConnectionFailureCode ) or ( 0 <> err.number ) ) then
- on error goto 0
- Set objServer = s_WMSAdmin.StartService( strServerName )
- if( IsEmpty( objServer ) ) then
- s_WMSAdmin.StartService( strServerName )
- Set objServer = s_WMSAdmin.Connect( strServerName )
- err.Clear
- end if
- g_dwConnectionFailureCode = s_WMSAdmin.GetServiceStatus( strServerName )
- end if
- if( WMS_SERVICE_STARTED = g_dwConnectionFailureCode ) then
- Set objServer = nothing
- Set objServer = s_WMSAdmin.Connect( strServerName )
- g_dwConnectionFailureCode = s_WMSAdmin.GetServiceStatus( strServerName )
-
- Set Session( "objCachedServer" ) = objServer
- Session( "strCachedServerName" ) = UCASE( strServerName )
- Session( "dwCachedServerStatus" ) = g_dwConnectionFailureCode
- Set Session( "objCachedPP" ) = Empty
- Session( "strCachedPPID" ) = ""
-
- err.Clear
- else
- on error goto 0
- ' recurse-- note that op has been changed to nothing
- g_strQueryStringServerOp = ""
- ConnectToNamedServer strServerName, "", objServer
- Exit Sub
- end if
- end if
-
- elseif( 0 = strcomp( "noop", strServerOp, vbTextCompare ) ) then
- Set objServer = Empty
-
- else
- if( 0 < Len( strServerName ) ) then
-
- Dim bDoExpensiveConnect
- bDoExpensiveConnect = TRUE
-
- '
- ' use cached server OM pointer, if possible
- '
- if( 0 = StrComp( UCASE( strServerName ), Session( "strCachedServerName" ) ) ) then
- if( Empty <> Session( "objCachedServer" ) ) then
- if( WMS_SERVICE_STARTED = Session( "dwCachedServerStatus" ) ) then
-
- on error resume next
- Set objServer = Session( "objCachedServer" )
- Session( "strCachedServerName" ) = UCASE( objServer.Name )
-
- if( ( 0 = err.number ) and ( 0 < Len( Session( "strCachedServerName" ) ) ) ) then
- bDoExpensiveConnect = FALSE
- g_dwConnectionFailureCode = WMS_SERVICE_STARTED
- else
- err.clear
- end if
-
- end if
- end if
- end if
-
- if( bDoExpensiveConnect ) then
- g_dwConnectionFailureCode = s_WMSAdmin.GetServiceStatus( strServerName )
- if( WMS_SERVICE_STARTED = g_dwConnectionFailureCode ) then
- if( ( nothing = objServer ) or ( empty = objServer ) ) then
- Set objServer = s_WMSAdmin.Connect( strServerName )
- g_dwConnectionFailureCode = s_WMSAdmin.GetServiceStatus( strServerName )
- err.Clear
-
- Set Session( "objCachedServer" ) = objServer
- Session( "strCachedServerName" ) = UCASE( strServerName )
- Set Session( "objCachedPP" ) = Empty
- Session( "strCachedPPID" ) = ""
- Session( "dwCachedServerStatus" ) = g_dwConnectionFailureCode
-
- end if
- end if
- end if
- end if
- end if
-
- if ( ( WMS_SERVICE_STARTED <> g_dwConnectionFailureCode ) or ( null = objServer ) or ( null = objServer ) ) then
- if( FALSE = Session( "ConnectionFailure" ) ) and ( CInt( qs("failCode") ) <> g_dwConnectionFailureCode )then
- if( WMS_SERVICE_STARTING = g_dwConnectionFailureCode ) then
- Session( "ConnectionFailure" ) = TRUE
- Response.Redirect( "/wmssecure/include/server_stopped.asp?server=" & g_strQueryStringServer & "&failCode=" & g_dwConnectionFailureCode )
- elseif( ( 0 <> StrComp( "/wmssecure/admin.asp", Request.ServerVariables( "PATH_INFO" ), vbTextCompare ) ) and ( 0 <> StrComp( "/wmssecure/include/server_stopped.asp", Request.ServerVariables( "PATH_INFO" ), vbTextCompare ) ) ) then
- Session( "ConnectionFailure" ) = TRUE
- Response.Redirect( "/wmssecure/include/server_stopped.asp?server=" & g_strQueryStringServer & "&failCode=" & g_dwConnectionFailureCode )
- elseif( 0 = StrComp( "connect", strServerOp, vbTextCompare ) )then
- Session( "ConnectionFailure" ) = TRUE
- Response.Redirect( "/wmssecure/include/server_stopped.asp?server=" & g_strQueryStringServer & "&serverop=" & strServerOp & "&failCode=" & g_dwConnectionFailureCode )
- end if
- end if
- end if
-
- if( objServer ) then
- g_strServerName = objServer.Name
- end if
- End Sub
-
- '////////////////////////////////////////////////////////////////
- '
- ' Called everywhere to establish connection to the WM Server.
- '
- Sub ConnectToServer()
- if( MAX_LEN_SERVERNAME < Len( g_strEncodedServerName ) ) then
- Exit Sub
- end if
-
- if( 0 < Len( g_strEncodedServerName ) ) then
- g_strServerName = g_strEncodedServerName
- g_strDecodedServerName = SafeUnescape( g_strServerName )
- else
- g_strServerName = ServerHashKeyToName( Request.Form.Item( "server" ) )
- g_strDecodedServerName = SafeUnescape( g_strServerName )
- end if
-
- call ConnectToNamedServer( g_strDecodedServerName, g_strQueryStringServerOp, g_objServer )
-
- End Sub
-
-
- '////////////////////////////////////////////////////////////////
- '
- ' Called from pub point pages to establish connection to the specified publishing point.
- '
- Sub ConnectToPubPoint()
- Dim strPPID
-
- ' always favor Pub Point ID over name
- strPPID = RemoveDangerousCharacters( CStr( trim( qs( "ppID" ) ) ) )
- if( 0 = Len( strPPID ) ) then
- strPPID = RemoveDangerousCharacters( trim( Request.Form( "ppID" ) ) )
- end if
-
- if( MAX_LEN_PPID < Len( strPPID ) ) then
- Exit Sub
- end if
-
- if( 0 < Len( strPPID ) ) then
- ConnectToPubPointID( strPPID )
- end if
- End Sub
-
-
- '////////////////////////////////////////////////////////////////
- Sub ConnectToPubPointID( strPPID )
- strPPID = CStr( trim( strPPID ) )
- if( ( 0 = Len( strPPID ) ) or ( MAX_LEN_PPID < Len( strPPID ) ) ) then
- Exit Sub
- end if
-
- lngPubPointIndex = 0
- g_objPubPoint = empty
- g_strPubPointID = strPPID
-
- Dim bDoExpensiveConnect
- bDoExpensiveConnect = TRUE
-
- if( 0 = StrComp( UCASE( strPPID ), Session( "strCachedPPID" ) ) ) then
- if( Empty <> Session( "objCachedPP" ) ) then
-
- on error resume next
- Set g_objPubPoint = Session( "objCachedPP" )
- Session( "strCachedPPID" ) = UCASE( g_objPubPoint.ID )
-
- if( ( 0 = err.number ) and ( 0 < Len( Session( "strCachedPPID" ) ) ) ) then
- bDoExpensiveConnect = FALSE
- else
- Session( "strCachedPPID" ) = ""
- err.clear
- end if
-
- end if
- end if
-
- if ( bDoExpensiveConnect and ( 0 < Len( g_strPubPointID ) ) ) then
- lngPubPointIndex = PPIDToIndex(g_objServer, strPPID )
- Set g_objPubPoint = g_objServer.PublishingPoints( lngPubPointIndex )
- else
- g_objPubPoint = Session( "objCachedPP" )
- end if
-
- g_strPubPointName = g_objPubPoint.Name
- g_strEncodedPubPointName = SafeEscape( g_objPubPoint.Name )
- End Sub
-
-
- '////////////////////////////////////////////////////////////////
- Sub ConnectToNamedPubPoint( strPPName )
- strPPName = CStr( trim( strPPName ) )
- if( ( 0 = Len( strPPName ) ) or ( MAX_LEN_PPNAME < Len( strPPName ) ) ) then
- Exit Sub
- end if
-
- g_strPubPointName = strPPName
- lngPubPointIndex = 0
- g_objPubPoint = empty
-
- if ( 0 < Len( g_strPubPointName ) ) then
- lngPubPointIndex = PPNameToIndex(g_objServer, g_strPubPointName )
- end if
-
- Set g_objPubPoint = g_objServer.PublishingPoints( lngPubPointIndex )
- g_strPubPointID = g_objPubPoint.ID
-
- Session( "objCachedPP" ) = g_objPubPoint
- Session( "strCachedPPID" ) = g_strPubPointID
- End Sub
-
-
- '////////////////////////////////////////////////////////////////
- '
- ' Stash the current page and query string into our global hash table
- '
- Sub LatchCurrentPage( strUrl, byRef querystring )
- ' g_strQueryStringServer = querystring( "server" )
-
- Dim strFullUrl
- Dim strKey
- Dim strItem
-
- if( 0 < Len( g_strQueryStringServer ) ) then
-
- strFullUrl = RemoveDangerousCharacters( strUrl ) & "?server=" & g_strQueryStringServer
- for intLoop = 1 to querystring.Count
- strKey = querystring.Key( intLoop )
- strItem = querystring.Item( intLoop )
- if( 0 <> StrComp( "server", strKey, vbTextCompare ) ) then
- if( 0 = StrComp( "ppID", strKey, vbTextCompare ) ) then
- strItem = SafeEscape( RemoveSpecifiedChars( strItem, REGEXP_DANGEROUS_PPID_CHARS ) )
- else
- strItem = SafeEscape( RemoveDangerousCharacters( strItem ) )
- end if
- strFullUrl = strFullUrl & "&" & RemoveDangerousCharacters( strKey ) & "=" & strItem
- end if
- next
-
- while( g_CurPageSessionHash.Exists( UCase( g_strQueryStringServer ) ) )
- g_CurPageSessionHash.Remove( UCase( g_strQueryStringServer ) )
- wend
-
- g_CurPageSessionHash.Add UCase( g_strQueryStringServer ), strFullUrl
- end if
- end Sub
-
- if( 0 = StrComp( "localhost", g_strDecodedServerName, vbTextCompare ) ) then
- g_strDecodedServerName = Application( "strLocalHostName" )
- end if
-
- '////////////////////////////////////////////////////////////////
- '
- ' Free the various globals we created by server-side-including this file
- '
- Sub WMSConnectASPCleanup
- on error resume next
-
- s_WMSAdmin = nothing
- g_objServer = nothing
- g_objPubPoint = nothing
- g_strServerName = nothing
- g_strPubPointName = nothing
-
- g_dwConnectionFailureCode = nothing
- g_bFailedToStartService = nothing
- g_strDecodedServerName = nothing
- g_strEncodedServerName = nothing
- g_strEncodedPubPointName = nothing
- g_strPubPointID = nothing
-
- g_strQueryString = nothing
- g_bSecureConnection = nothing
-
- ' Depricated means of determining browser
- g_bMSIE = nothing
- g_bNetscape = nothing
- g_bOpera = nothing
-
- ' New means of determining browser
- g_dwBrowserType = nothing
- g_curBrowserVersion = nothing
- g_strUserAgent = nothing
- g_strQueryStringServer = nothing
- g_strQueryStringServerOp = nothing
- g_CurPageSessionHash = nothing
-
- qs = nothing
- posting = nothing
- End Sub
- %>